<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../lib/vue.main.js"></script>
</head>

<body>
    <div id="app">
        <div>
            <label>
                Id:<input type="text" v-model='id'></input>
            </label>
            <label>
                Name:<input type="text" v-model='name'></input>
            </label>
            <input type="button" value="添加" @click="add"></input>
        </div>
        <!-- v-for循环的时候,key属性只能使用number获取string(2.6.10版本已经适配) -->
        <p v-for="item in list" :key="item.id">
            <input type="checkbox">{{item.id}} --- {{item.name}}
        </p>
    </div>
    <script>
        var vm=new Vue({
           el:'#app',
           data:{
               id:'',
               name:'',
               list:[
                   {id:1,name:'李斯'},
                   {id:2,name:'嬴政'},
                   {id:3,name:'韩非'},
                   {id:4,name:'赵高'}
               ]
           },
           methods:{
               add(){//添加方法
                   this.list.unshift({id:this.id,name:this.name});
               }
           }
        });
    </script>
</body>

</html>